package com.zfast.config.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
//import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;

/**
 * @Classname User
 * @Description None
 * @Date 2019/7/16 12:03
 * @Created by WDD
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "t_sys_user")
//@ApiModel(value = "User", description = "系统用户")
public class User implements UserDetails {
    @Id
    //@KeySql(genId = tk.mybatis.mapper.genid.GenId.class)//mybatis 的自动id
    @GenericGenerator(name = "user-uuid", strategy = "uuid")
    @GeneratedValue(generator = "user-uuid")
    private String id;

    @Column(name = "username")
    private String username;
    private String password;
    private String phone;
    private String email;
    private String rid;
    private Integer status; // 0为待审核，1为通过
    private String createtime;

    //添加元素
    @Transient
    private String roleName;
    @Transient
    private List<Role> roles;


    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
